import {createAlova} from 'alova';
import ReactHook from 'alova/react';
import adapterFetch from 'alova/fetch';

export const alovaHttp = createAlova({
    baseURL: '/dev-api',
    requestAdapter: adapterFetch(),
    statesHook: ReactHook,
    responded: async response => {
        try {
            const body = await response.json()
            return body['data']
        } catch (e) {
            return {}
        }
    },
    beforeRequest(method) {
        console.log('method.config.headers',)
        if (typeof method.config.headers['X-Requested-With'] === 'undefined') {
            method.config.headers['X-Requested-With'] = 'xmlhttprequest'
        }
    }
});